package cup.com.icss.utils;

import org.apache.log4j.Logger;

/**
 * 日志工具类
 * 
 * @Title: LogUtil.java
 * @Package com.icss.synergy.common.util
 * @author james
 * @date 2012-7-18 下午15:40:24
 * @version V1.0
 * 
 * 使用规则：
 * 1、调试信息一律用debug
 * 2、重要信息用info
 * 3、错误信息一律用error
 */
public class LogUtil {
	public LogUtil() {
	}

	private static Logger errorLog = Logger.getLogger("OA_ERROR");
	private static Logger infoLog = Logger.getLogger("OA_INFO");
	private static Logger debugLog = Logger.getLogger("OA_DEBUG");

	/**
	 * error日志
	 * 
	 * @Title: errorLog
	 * @param e
	 *            异常
	 */
	public static void errorLog(Exception e) {
	    System.err.println("\n ");
        errorLog.error("\n ");
		System.err.println("OA ERROR - " + e.getMessage());
		errorLog.error("error is:" + e.getMessage());
		StackTraceElement[] elements = e.getStackTrace();
		for (int i = 0; i < elements.length; i++) {
			StackTraceElement element = elements[i];
			System.err.println("OA ERROR - " + element.toString());
			errorLog.error(element.toString());
		}
	}
	
	/**
	 * error日志
	 * 
	 * @Title: errorLog
	 * @param contextName	应用上下文名称
	 * @param e
	 *            异常
	 */
	public static void errorLog(String contextName,Exception e) {
		contextName = contextName.toUpperCase().replace("/", "");
	    System.err.println("\n ");
        errorLog.error("\n ");
		System.err.println(contextName + " ERROR - " + e.getMessage());
		errorLog.error("error is:" + e.getMessage());
		StackTraceElement[] elements = e.getStackTrace();
		for (int i = 0; i < elements.length; i++) {
			StackTraceElement element = elements[i];
			System.err.println(contextName+ " ERROR - " + element.toString());
			errorLog.error(element.toString());
		}
	}

	/**
	 * 
	 * @Title: errorLog
	 * @author: JamesWang
	 * @date 2012-7-16 下午15:18:36
	 * @param claz
	 *            类名
	 * @param desc
	 *            描述
	 * @param e
	 *            异常
	 */
	public static void errorLog(Class claz, String desc, Exception e) {
	    System.err.println("\n");
        errorLog.error("\n");
        System.err.println("OA ERROR - " + claz.getName() + "#" + desc + ": " + e.getMessage());
        System.err.println("error is: " + e);
		errorLog.error(claz.getName() + "#" + desc + ": " + e.getMessage());
		errorLog.error("error is: " + e);
		StackTraceElement[] elements = e.getStackTrace();
		for (int i = 0; i < elements.length; i++) {
			StackTraceElement element = elements[i];
			System.err.println("OA ERROR - " + element.toString());
			errorLog.error(element.toString());
		}
	}
	
	/**
	 * 
	 * @Title: errorLog
	 * @author: JamesWang
	 * @date 2012-7-16 下午15:18:36
	 * @param contextName	应用上下文名称
	 *  
	 * @param claz
	 *            类名
	 * @param desc
	 *            描述
	 * @param e
	 *            异常
	 */
	public static void errorLog(String contextName,Class claz, String desc, Exception e) {
		contextName = contextName.toUpperCase().replace("/", "");
	    System.err.println("\n");
        errorLog.error("\n");
        System.err.println(contextName + " ERROR - " + claz.getName() + "#" + desc + ": " + e.getMessage());
        System.err.println("error is: " + e);
		errorLog.error(claz.getName() + "#" + desc + ": " + e.getMessage());
		errorLog.error("error is: " + e);
		StackTraceElement[] elements = e.getStackTrace();
		for (int i = 0; i < elements.length; i++) {
			StackTraceElement element = elements[i];
			System.err.println(contextName + " ERROR - " + element.toString());
			errorLog.error(element.toString());
		}
	}

	/**
	 * error日志
	 * 
	 * @Title: errorLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param desc
	 *            日志信息
	 */
	public static void errorLog(Class claz, String method, Object desc) {
		System.err.println("OA ERROR - " + claz.getName() + "#" + method + ": " + desc);
		errorLog.error(claz.getName() + "#" + method + ": " + desc);
		
	}
	
	/**
	 * error日志
	 * 
	 * @Title: errorLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param contextName	应用上下文名称
	 *   
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param desc
	 *            日志信息
	 */
	public static void errorLog(String contextName,Class claz, String method, Object desc) {
		contextName = contextName.toUpperCase().replace("/", "");
		System.err.println(contextName + " ERROR - " + claz.getName() + "#" + method + ": " + desc);
		errorLog.error(claz.getName() + "#" + method + ": " + desc);
		
	}

	/**
	 * info日志
	 * 
	 * @Title: sysLog
	 * @param obj
	 */
	public static void infoLog(Object obj) {
		System.out.println("OA INFO - " + obj);
		infoLog.info(obj);
	}
	
	/**
	 * info日志
	 * 
	 * @Title: sysLog
	 * @param contextName	应用上下文名称
	 * @param obj
	 */
	public static void infoLog(String contextName,Object obj) {
		contextName = contextName.toUpperCase().replace("/", "");
		System.out.println(contextName + " INFO - " + obj);
		infoLog.info(obj);
	}

	/**
	 * info日志
	 * 
	 * @Title: infoLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param obj
	 *            日志信息
	 */
	public static void infoLog(Class claz, String method, Object obj) {
		System.out.println("OA INFO - " + claz.getName() + "#" + method
				+ ": " + obj);
		infoLog.info(claz.getName() + "#" + method + ": " + obj);
	}
	
	/**
	 * info日志
	 * 
	 * @Title: infoLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param contextName	应用上下文名称
	 * 
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param obj
	 *            日志信息
	 */
	public static void infoLog(String contextName,Class claz, String method, Object obj) {
		contextName = contextName.toUpperCase().replace("/", "");
		System.out.println(contextName + " INFO - " + claz.getName() + "#" + method
				+ ": " + obj);
		infoLog.info(claz.getName() + "#" + method + ": " + obj);
	}

	/**
	 * debug日志
	 * 
	 * @Title: debugLog
	 * @param obj
	 */
	public static void debugLog(Object obj) {
		System.out.println("OA DEBUG - " + obj);
		debugLog.debug(obj);
	}
	
	/**
	 * debug日志

	 * @Title: debugLog
	 * @param contextName	应用上下文名称
	 * @param obj
	 */
	public static void debugLog(String contextName,Object obj) {
		contextName = contextName.toUpperCase().replace("/", "");
		System.out.println(contextName + " DEBUG - " + obj);
		debugLog.debug(obj);
	}

	/**
	 * debug日志
	 * 
	 * @Title: debugLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param obj
	 *            日志信息
	 */
	public static void debugLog(Class claz, String method, Object obj) {
		System.out.println("OA DEBUG - " + claz.getName() + "#" + method
				+ ": " + obj);
		debugLog.debug(claz.getName() + "#" + method + ": " + obj);
	}
	
	/**
	 * debug日志
	 * 
	 * @Title: debugLog
	 * @author: JamesWang
	 * @date 2012-7-18 下午15:40:24
	 * @param contextName	应用上下文名称
	 * 
	 * @param claz
	 *            类名
	 * @param method
	 *            方法名
	 * @param obj
	 *            日志信息
	 */
	public static void debugLog(String contextName,Class claz, String method, Object obj) {
		contextName = contextName.toUpperCase().replace("/", "");
		System.out.println(contextName +  " DEBUG - " + claz.getName() + "#" + method
				+ ": " + obj);
		debugLog.debug(claz.getName() + "#" + method + ": " + obj);
	}
}
